

var ssopts = {
	init: function() {
		var tc = SS_getPreference(SMACK_TCHL1);
		var bc = SS_getPreference(SMACK_BTCHL1);
		ssopts.updateSample(tc,bc);
		/*
		var cpicker = document.getElementById('tcolorpic1');
		var cpicker2 = document.getElementById('bkcolorpic1');
		
		
		var usercolor = SS_getPreference(SMACK_TCHL1);
		cpicker.color = usercolor;
		usercolor = SS_getPreference(SMACK_BTCHL1);
		cpicker2.color = usercolor;
		*/
		
	},
	updateTextColor: function() {
		var cpicker = document.getElementById('tcolorpic1');
		var textColor = document.getElementById('textstringpref_hltextcolor1');
		textColor.value = cpicker.color;
		ssopts.updateSample(textColor.value, null);
	},
	updateBackgroundColor: function() {
		var cpicker = document.getElementById('bkcolorpic1');
		var textColor = document.getElementById('textstringpref_hlbkcolor1');
		textColor.value = cpicker.color;
		ssopts.updateSample(null, textColor.value);
	},
	textboxColorChange: function(event) {
		var textColor = event.target;
		var newcolor;
		if (textColor.id == 'textstringpref_hlbkcolor1') {
		var cpicker = document.getElementById('bkcolorpic1');
		cpicker.color = textColor.value;
		ssopts.updateSample(null, textColor.value);
		}
		else if(textColor.id == 'textstringpref_hltextcolor1') {
			var cpicker = document.getElementById('tcolorpic1');
			cpicker.color = textColor.value;
			ssopts.updateSample(textColor.value,null);
		}
		
	},
	themeColorChange: function(textColor,backgroundColor) {
		document.getElementById('textstringpref_hltextcolor1').value = textColor;
		SS_prefs.setCharPref(SMACK_TCHL1,textColor);
		document.getElementById('textstringpref_hlbkcolor1').value = backgroundColor;
		SS_prefs.setCharPref(SMACK_BTCHL1,backgroundColor);
		ssopts.updateSample(textColor,backgroundColor);
	},
	updateSample: function(tc, bc) {
		var l = document.getElementById('hlSampleText');
		if (tc != null) l.style.color=tc;
		if (bc != null) l.style.background=bc;
	},
	selectAudio: function() {
		var am = SS_AUDIO;
		if (am == null) am = new AudioManager();
		var fc = new FileChooser('Select Audio File',am);
		fc.open();
	},
	playAudio: function() {
		var af = document.getElementById('audioFile').value;
		var am = SS_AUDIO;
		if (am == null) am = new AudioManager();
		am.playAudioAlert(af);
	},
	resetAudio: function() {
		var af = document.getElementById('audioFile').value;
		var answer = confirm('Reset audio to default value?');
		if (answer) {
			var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBranch("");
	 		if (prefs == null) return;
			var optionitems = new Array();
	 		optionitems = optionitems.concat(SMACK_AUDIO_OPTIONITEMS);
	 		for (var i=optionitems.length-1;i>=0;i--){
			 	try {
			 		prefs.clearUserPref(optionitems[i]);
			 	} catch (Exception){}
			}
		}
	},
	resetIgnorePrefs: function() {
	 var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBranch("");
	 if (prefs == null) return;
	 var answer = confirm("Reset Ignore/Block SwakSmack preferences?");
	 if (answer) {
	 	try {
	 		var optionitems = new Array();
	 		optionitems = optionitems.concat(SMACK_IGNORE_OPTIONITEMS);
	 		for (var i=optionitems.length-1;i>=0;i--){
		 	try {
		 		prefs.clearUserPref(optionitems[i]);
		 	} catch (Exception){}
		}
	 }
	 catch (Exception ) {alert('error: ' + Exception);}
	 }
	},
	resetAllPrefs: function() {
					
		//var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBranch("extensions.swaksmack.");
		var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBranch("");
		//var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
	  if (prefs == null) return;
		var answer = confirm("Reset All SwakSmack preferences?");
		if (answer) {
		 try {
		 	var optionitems = new Array();
		 	optionitems = optionitems.concat(SMACK_OPTIONITEMS);
		 	optionitems = optionitems.concat(SMACK_IGNORE_OPTIONITEMS);
		 	optionitems = optionitems.concat(SMACK_ADV_OPTIONITEMS);
		 	optionitems = optionitems.concat(SMACK_AUDIO_OPTIONITEMS);
		 	
		 	for (var i=optionitems.length-1;i>=0;i--){
		 		try {
		 			prefs.clearUserPref(optionitems[i]);
		 		} catch (Exception){}
			}
			
		 
		// var r = prefs.deleteBranch("extensions.swaksmack."); //works, but you need to manually reset the prefs to default values
		// var r = prefs.clearUserPref(SMACK_ENABLEHL);  //works on individual prefs
		 //var r = prefs.resetBranch("extensions.swaksmack"); //not implemented

		 }
		 catch (Exception ) {alert('error: ' + Exception);}
		}
	}
} //end ssopts
